package com.c.ctgproject.adapter.guang

import android.content.Context
import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.*
import androidx.appcompat.widget.LinearLayoutCompat
import androidx.recyclerview.widget.RecyclerView
import com.c.ctgproject.R
import com.c.ctgproject.base.BaseEmptyRecyclerViewAdapterV2
import com.c.ctgproject.entity.guang.*
import com.c.ctgproject.ui.collect.*
import com.c.ctgproject.ui.collect.check.OutCheckDetailActivity
import com.c.ctgproject.utils.MyConstants
import com.c.ctgproject.utils.getGson
import com.c.ctgproject.utils.handlerNull
import com.c.ctgproject.utils.noDataHandler
import org.jetbrains.anko.backgroundColor
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.textColor
import org.jetbrains.anko.textColorResource
/**type 1电池 2零部件*/
class OutCommonAdapter(private val context: Context, private val mList: List<OutCommonEntity.DataBean.ListBean>,private val mType:Int=-1,private val listener:OutCommonCallBack) : BaseEmptyRecyclerViewAdapterV2(context, mList) {
    override fun createViewHolder(parent: ViewGroup): RecyclerView.ViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_out_common_list, parent, false)
        return MyViewHolder(view)
    }

    override fun handlerData(holder: RecyclerView.ViewHolder, position: Int) {
        if (holder is MyViewHolder) {
            val data = mList[position]
            holder.mUserNameTV.text = data.createPersonName.noDataHandler()
            holder.mTimeTV.text = data.createTime.noDataHandler()
            holder.mNo.text = data.bizNo.noDataHandler()
            holder.mClientTV.text = data.customer.noDataHandler()

            val outType = when (data.outType) {
                1 -> "销售出库"
                2 -> "借用出库"
                3 -> "其他出库"
                else -> "暂无数据"
            }
            holder.outType.text = outType

            when{
                data.status==0->{
                    holder.mStatueTV.text="草稿单"
                    holder.mStatueTV.textColor=Color.parseColor("#e6a23c")
                }
                data.status==1->{
                    holder.mStatueTV.text="待审批"
                    holder.mStatueTV.textColor=Color.parseColor("#aaaaaa")

                }
                data.status==2&&data.isReject==1->{
                    holder.mStatueTV.text="已拒绝"
                    holder.mStatueTV.textColor=Color.parseColor("#ff4949")

                }
                data.status==2&&data.isReject==0->{
                    holder.mStatueTV.text="已同意"
                    holder.mStatueTV.textColor=Color.GREEN
                }
            }



//            val dismantleMethod = when (data.outType) {
//                1 -> "销售出库"
//                2 -> "借用出库"
//                3 -> "其他出库"
//                else -> "暂无数据"
//            }
//            holder.dismantleMethod.text = dismantleMethod
//
//
            holder.mParentLL.setOnClickListener {
                //查看详情
                context.startActivity<OutCheckDetailActivity>(
                    MyConstants.ID to data.outOrderId,
                    MyConstants.JUST_SHOW to true,
                    MyConstants.DATA_TYPE to mType
                )

//                context.startActivity<PartDetailActivity>(MyConstants.ORDER_ID to data.orderId)
//                context.startActivity<BatteryDetailActivity>(MyConstants.ORDER_ID to data.orderId)
            }
            //holder.mDeleteBTN.visibility=if(data.isRemove==1)View.VISIBLE else View.GONE
            holder.mDeleteBTN.visibility=View.GONE
            holder.mDeleteBTN.setOnClickListener {
                listener.itemDelete(position,data)
            }
        }
    }

    interface OutCommonCallBack{
        fun itemDelete(position: Int,data:OutCommonEntity.DataBean.ListBean)
    }
    inner class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val outType: TextView = view.findViewById(R.id.mType)
        val mStatueTV: TextView = view.findViewById(R.id.mStatueTV)
        val mUserNameTV: TextView = view.findViewById(R.id.mUserNameTV)
        val mNo: TextView = view.findViewById(R.id.mNo)
        val mTimeTV: TextView = view.findViewById(R.id.mTimeTV)

        //        val dismantleMethod: TextView = view.findViewById(R.id.dismantleMethod)
//        val mBTN: Button = view.findViewById(R.id.mBTN)
        val mParentLL: LinearLayoutCompat = view.findViewById(R.id.mParentLL)
        val mClientTV: TextView = view.findViewById(R.id.mClientTV)
        val mDeleteBTN:Button=view.findViewById(R.id.mDeleteBTN)
    }


}